@extends('master/master_index')

@section('title')
    <title>信息修改</title>
@endsection

@section('css')
    <link rel="stylesheet" type="text/css" href="{{asset('home/css/Topic_UserCenter.css')}}">
@endsection

@section('content')
    <div class="user_pro_wrap">
        <div class="upw_content">
            <div class="upw_top">
                <i class="Hui-iconfont">&#xe647;</i>
                编辑个人资料
            </div>
            <form class="pro_update" action="{{url('profile_update')}}" method="post" id="form1" enctype="multipart/form-data">
                <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                <lable for="name">昵称</lable>
                <input type="text" name="name" id="name" value="{{$user['username']}}"><br/>
                <lable for="email">邮箱</lable>
                <input type="text" name="email" id="email"  readonly="true" value="{{$user['email']}}"><br/>
                <lable for="gender">性别</lable>
                <select name="gender" id="">
                    <option value="1" >男</option>
                    <option value="0" @if($user->profile->gender==0) selected="selected"@endif>女</option>
                </select><br/>
                <lable for="real_name">真实姓名</lable>
                <input type="text" name="real_name" id="real_name" value="@if ($user->profile['real_name']){{$user->profile['real_name']}}@endif"><br/>
                <lable for="tel">电话</lable>
                <input type="number" name="tel" id="tel" value="@if (($user->profile['tel'])){{$user->profile['tel']}}@endif"><br/>
                <lable for="city">城市</lable>
                <input type="text" name="city" id="city" value="@if (($user->profile['city'])){{$user->profile['city']}}@endif"><br/>
                <div class="image">
                    <label >头像</label><br/>
                    <img class="avatar" src="{{asset('home/img/avatar/first_avatar.png')}}" />
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>点击图片上传文件</span>
                </div>
                <div style="display: none;">
                    <input id="image" name="image" type="file" />
                </div>
                <lable for="signature">简介</lable><br/>
                <textarea name="signature" id="signature" cols="43" rows="8">@if (($user->profile['signature'])){{$user->profile['signature']}}@endif</textarea>
                <button class="btn">提交修改</button>
            </form>
        </div>
    </div>
@endsection

@section('js')
    <script type="text/javascript">
            document.querySelector('.btn').onclick=function(){
                document.querySelector('#form1').submit();
            }
            var goodImg = document.querySelector('.avatar');
            // 点击图片img元素，触发文件选择
            goodImg.onclick = function() {
                document.getElementById('image').click();
            };
            // 获取到用户选择的文件
            document.getElementById('image').onchange = function() {
                var fileReader = new FileReader();
                fileReader.onload = function() {
                    if (fileReader.readyState === FileReader.DONE) {
                        goodImg.src = this.result;
                    }
                }

                if (this.files.length > 0) {
                    fileReader.readAsDataURL(this.files[0]);
                }
            };
    </script>
@endsection